<?php 
class mysqlClass {
	
	private $error;
	private $connect;
	/**
	 * Connect to mysql database
	 * param:$host,$user,$pword,$name
	 */
	function __construct()
	{
		$this->error='';
	}	
	
	public function connect ($host,$user,$pword,$name)
	{
		$this->connect = mysql_connect($host,$user, $pword) or $this->error .= mysql_error();
		mysql_select_db($name, $this->connect) or $this->error .= mysql_error();
		if ($this->error=='')
			return true;
		else
			return false;	
	}
	
	/**
	 * return the error
	 */
	public function getError()
	{
		return $this->error;
	}
	
	/***
	 * close db
	 */
	public function close()
	{
		mysql_close($this->connect);
	}
	
	/**
	 * execute query, return ris
	 */
	public function query($sql)
	{
		return mysql_query($sql,$this->connect);
	}
	
	/**
	 * fetch result and return array ass
	 */
	public function fetcharray($result)
	{
		$res=array();
		while ($row = mysql_fetch_assoc($result)) {
			$res[]=$row; }
		return $res;
	}
	
	static public function affectedrows()
	{
		return mysql_affected_rows($this->connect);
	}
}
